'use strict';

const Service = require('egg').Service;

class UserService extends Service {
    async 0(stu){
        let res=await this.app.mysql.query(`select * from manager_user where stu='${stu}' and pwd='${pwd}'`)
        return res;
    }


  async getuser() {
    let res=await this.app.mysql.query(`select*from manager_user where stu=${stu}`);
    return res;
  }
  async registry(obj){
      let {name,pwd,stu,role}=obj
      let res=await this.app.mysql.query(`insert into manager_user (name,pwd,stu,role) values ('${name}','${pwd}','${stu}','${role}')`)
    return res;
    }
  

    async login(obj){
        let {stu,pwd}=obj;
        let res=await this.app.mysql.query(`select * from manager_user where stu='${stu}' and pwd='${pwd}'`)
        return res;
    }

    async getmenu(rid){
        let pid=`select*from role_power where rid='${rid}'`;
        let sql=`select * from power where id in (${pid})`;
        // await this.app.mysql.query(sql);
        let res=await this.app.mysql.query(sql);
       
        let name=await this.app.mysql.query(`select rname from role where id=${rid}`);
        
         return {
             res,
             username:username[0].name,
             rname:name[0].rname
         };
     }

     async getstudent(){
         let sql=`select stu from scores`;
         let sql2=`select * from manager_user where stu not in (${sql}) and not role=1`;
         let res=await this.app.mysql.query(sql);
         return res;
     }
}

module.exports = UserService;
